

PRO MFN_SLICE_DICE
  
  COMPILE_OPT IDL2, LOGICAL_PREDICATE
  
  COMMON OMNI_CONFIG, conf, mw, local, dpdfs, ancil, fmt, conffile
  
  RESOLVE_ROUTINE, 'make_physical_plots', /EITHER, /COMPILE_FULL_FILE, $
                   /NO_RECOMPILE
  
  ;; Read in survey-info, galactic-params, & dpdf-params config files
  conf     = omni_load_conf(cfile)
  mw       = omni_read_conffile('./conffiles/galactic_params.conf')
  dpdfs    = omni_read_conffile('./conffiles/dpdf_params.conf')
  mconf    = omni_read_conffile('./conffiles/mass_deriv.conf')
  d        = dindgen(dpdfs.nbins)*dpdfs.binsize + dpdfs.binstart
  
  ;; Some physics for a little later...
  bigG  = 6.67384d-11                 ; Gravitation        [m^3 kg^-1 s^-2]
  c     = 299792458.d                 ; Speed of Light     [m/s]
  h     = 6.626068d-34                ; Planck constant    [m^2 kg s^-1]
  kb    = 1.3806503d-23               ; Boltzmann constant [m^2 kg s^-2 K^-1]
  Jy    = 1.d-26                      ; Jansky             [W m^-2 Hz^-1]
  hnuk  = h*conf.nu/kb                ; h*nu/kb            [K]
  msun  = 1.9891d30                   ; Solar Mass         [kg]
  pc    = 3.08567758d16               ; parsec             [m]
  mu    = 2.8                         ; Avg molecular mass
  mh    = 1.673723599d-24             ; Hydrogen Mass      [g] 
  kappa = conf.kappa/10.d/mw.gas2dust ; dust opactiy       [m^2 kg^-1]
  
  ;; Fiducial mass surface density, modulo flux density (Jy) and size (")
  S0   = c * c * Jy * (exp(hnuk/mw.td) - 1.d) * 206265.d * 206265.d / $
         (2.d * kappa * h * conf.nu*conf.nu*conf.nu*!dpi) * 1.d-1 ; [g cm^-2]
  
  
  ;;=============================================
  ;; Routine to slice up the latest MFN output from
  ;;   omni_mass_function,/mfnsave into the various pre-determined
  ;;   subsets.  It's a party that never wanted to happen.
  
  tempstr = ['20K','LogNormal']
  
  FOR it=0,1 DO BEGIN
     
     stdst = string(it,format="(I0)")
     
     ;; Create mass function for use here (sampletd = [0,1])
     message,'Creating SAMPLETD='+stdst+' mass function',/inf
     OMNI_MASS_FUNCTION, CONFFILE=cfile, /MEGA, NREAL=nreal, SAMPLETD=it, $
                         /MFNSAVE, MFNFN=fn, /SILENT
     sampletd = it
     restore,fn,/ver
     ;; Restore the velocity structure, and align it with the S from
     ;;   the MFN save file.
     restore,'./local/'+conf.survey+'_velocities.sav'
     restore,'./local/'+conf.survey+'_dunham_mir.sav'
     vind = where_array(s.cnum,v.cnum,vct)
     IF vct NE n_elements(s) THEN message,'Time for vodka shots, dude.'
     v   = v[vind]
     mir = mir[vind]
     
     ;; Compute Rgal, Zgal
     glon = cmreplicate(s.glon,n_elements(objs))
     glat = cmreplicate(s.glat,n_elements(objs))
     OMNI_LBD2RZ,glon,glat,objs.dist,rgal,zgal,XGAL=xgal,YGAL=ygal
     
     ;; Aspect Ratio
     aspe = cmreplicate(s.maj / s.min, n_elements(objs))
     sfac = cmreplicate(mir.group,     n_elements(objs))
     
     ;; Make some arrays for use in computing physical quantities
     arsz = size(objs.dist,/DIM)
     nele = n_elements(objs.dist)
     
     ;; Place data into standardized arrays
     flux = cmreplicate(s.(iflux),n_elements(objs)) ; Flux density [Jy]
     dist = objs.dist / 1.d3                        ; Distance [kpc]
     arad = cmreplicate(s.rad,n_elements(objs))     ; Angular rad [arcsec]
     tdus = temp.objs                               ; Temperature [K]
     linw = cmreplicate(v.grs.lw,n_elements(objs))  ; 13CO Linewidth [km/s]
     dglw = cmreplicate(v.lw,n_elements(objs))      ; d.g. Linewidth [km/s]
     rgal /= 1.d3                                   ; R_gal [kpc]
     
     ;; cgPlot,dist,zgal,/nodata,charsize=1.0,xtit='D',ytit='Z'
     ;; MAKE_PHYSICAL_PLOTS_PLOT, dist,zgal, XR=[0,20],yr=[-400,600],NBOX=200
     
     
     ;; Compute derived quantities
     radi = arad / 206265.d * (dist * 1.d3)              ; Physical radius [pc]
     tcor = (exp(hnuk/tdus)-1.d) / (exp(hnuk/mw.td)-1.d) ; Temp correction
     mass = m0 * flux * dist * dist * tcor * conf.fluxcor      ; M_sun
     dens = mass * msun/ (!dpi*radi*radi*radi*pc*pc*pc) / 1.d3 ; g/cc 
     nden = dens / (mu*mh)                                     ; cm^-3
     sden = S0 * flux / (arad * arad) * tcor                   ; g cm^-2
     cden = sden / (mu*mh)                                     ; cm^-2
     avir = 5.d*(linw*linw*1.d6)*(radi*pc)/bigG/(mass*msun)    ; [unitless]
     avdg = 5.d*(dglw*dglw*1.d6)*(radi*pc)/bigG/(mass*msun)    ; [unitless]

     ;; Make byte array of elements that have distance in proper range
     usei = dist GE mconf.dmin AND dist LE mconf.dmax AND $
            radi GE mconf.rmin AND radi LE mconf.rmax AND $
            nden GE mconf.nmin AND nden LE mconf.nmax
     fini = finite(arad)
     
     ;; Using USEI, make 1-D arrays of physical properties for
     ;;   'keeper' objects 
     iu = where(usei)
     d  = dist[iu]
     m  = mass[iu]
     r  = radi[iu]
     n  = nden[iu]
     nh = cden[iu]
     sd = sden[iu]
     rg = rgal[iu]
     zg = zgal[iu]
     ar = aspe[iu]
     xg = xgal[iu] / 1.d3
     yg = ygal[iu] / 1.d3
     av = avir[iu]
     dv = avdg[iu]
     
     ;; nbox = 200
     ;; xr = [-15,10]
     ;; yr = [-15,10]
     ;; MAKE_PHYSICAL_PLOTS_PLOT,yg,xg,NBOX=nbox,xr=xr,yr=yr,HIST=hist
     ;; Plot,yg,xg,/nodata,xr=xr,yr=yr,/isotropic
     ;; xc = (findgen(nbox+1)+0.5)/nbox*(xr[1]-xr[0]) + xr[0]
     ;; yc = (findgen(nbox+1)+0.5)/nbox*(yr[1]-yr[0]) + yr[0]
     ;; help,median(alog10(hist),5),hist
     ;; cgSurface,median(alog10(hist),5);,xc,yc,/over,label=0,c_color='wt1'
     
     
     
     ;;==========================================================
     ;; Make big multiplot of histograms
     
     myps,'./masses/plots/cuts_histograms_td'+stdst+'.eps',xsize=11,ysize=10
     multiplot_xm,[3,3],ygap=0.03,xgap=0.04,mpcharsize=1.0,/doxaxis,/doyaxis,$
                  mtitle='T!dd!n = '+tempstr[it]
     
     
     ;;############################################
     ;; Heliocentric Distance
     plothist,d,bin=0.2,charsize=1.0,xtit='D  [kpc]',$
              ytickformat='exponent'
     
     dplot = 0
     REPEAT BEGIN
        vline,dplot,color='cyan'
        dplot += 2
     ENDREP UNTIL dplot GT !x.crange[1]
     
     multiplot,/doxaxis,/doyaxis
     
     ;;############################################
     ;; Mass
     plothist,alog10(m),bin=0.1,xarr,yarr,/noplot
     cgPlot,xarr,yarr,psym=10,xst=4,ytickformat='exponent',charsize=1.0
     cgAxis,xaxis=0,xr=10.^(!x.crange),/xst,/save,charsize=1.0,$
            xtit='M  [M'+cgSymbol('sun')+']',/xlog
     cgAxis,xaxis=1,/xst,xtickformat='blank_axis'
     
     al_legend,/top,/left,box=0,textcolor='red',$
               ['This is what we want for the various cuts']
     
     multiplot,/doxaxis,/doyaxis
     
     ;;############################################
     ;; Physical Radius
     plothist,alog10(r),bin=0.1,xarr,yarr,/noplot
     cgPlot,xarr,yarr,psym=10,xst=4,ytickformat='exponent1',charsize=1.0,$
            xr=[-2,1]
     cgAxis,xaxis=0,xr=10.^(!x.crange),/xst,/save,charsize=1.0,$
            xtit='R  [pc]',/xlog,xtickformat='exponent10'
     cgAxis,xaxis=1,/xst,xtickformat='blank_axis'
     
     vline,0.125,color='blu3'
     vline,1.25,color='blu3'
     
     
     multiplot,/doxaxis,/doyaxis
     
     ;;############################################
     ;; Number Density
     plothist,alog10(n),bin=0.1,xarr,yarr,/noplot
     cgPlot,xarr,yarr,psym=10,xst=5,ytickformat='exponent',charsize=1.0,$
            xr=[1.5,5.5]
     cgAxis,xaxis=0,xr=10.^(!x.crange),/xst,/save,charsize=1.0,$
            xtit='n  [cm!u-3!n]',/xlog,xtickformat='exponent10'
     cgAxis,xaxis=1,/xst,xtickformat='blank_axis'
     
     vline,750,color='blu3'
     vline,1.d4,color='blu3'
     
     multiplot,/doxaxis,/doyaxis
     
     ;;############################################
     ;; Column Density
     plothist,alog10(nh),bin=0.1,xarr,yarr,/noplot
     cgPlot,xarr,yarr,psym=10,xst=4,ytickformat='exponent1',charsize=1.0
     cgAxis,xaxis=0,xr=10.^(!x.crange),/xst,/save,charsize=1.0,$
            xtit='N!dH!i2!n  [cm!u-2!n]',/xlog,xtickformat='exponent10'
     cgAxis,xaxis=1,/xst,xtickformat='blank_axis'
     
     multiplot,/doxaxis,/doyaxis
     
     ;;############################################
     ;; Mass Surface Density
     ;; plothist,alog10(sd),bin=0.1,xarr,yarr,/noplot
     ;; cgPlot,xarr,yarr,psym=10,xst=4,ytickformat='exponent1',charsize=1.0
     ;; cgAxis,xaxis=0,xr=10.^(!x.crange),/xst,/save,charsize=1.0,$
     ;;        xtit=cgSymbol('Sigma')+'  [g cm!u-2!n]',/xlog,$
     ;;        xtickformat='exponent10'
     ;; cgAxis,xaxis=1,/xst,xtickformat='blank_axis'
     
     ;; al_legend,/top,/right,textcolor='red',box=0,$
     ;;           ['Direct scaling','of previous']
     
     multiplot,/doxaxis,/doyaxis
     
     ;;############################################
     ;; Galactocentric Radius
     plothist,rg,bin=0.2,charsize=1.0,xtit='R!dgal!n  [kpc]',$
              ytickformat='exponent'
     
     dplot = 0
     REPEAT BEGIN
        IF dplot GT !x.crange[0] THEN $
           vline,dplot,color='cyan'
        dplot += 2
     ENDREP UNTIL dplot GT !x.crange[1]
     
     multiplot,/doxaxis,/doyaxis
     
     ;;############################################
     ;; Galactocentric Height
     plothist,zg,bin=10,charsize=1.0,xtit='z!dgal!n  [pc]',$
              ytickformat='exponent1',xr=[-200,200]
     
     multiplot,/doxaxis,/doyaxis
     
     ;;############################################
     ;; Virial Parameter
     plothist,alog10(dv[where(dv GT 0)]),bin=0.1,xarr,yarr,/noplot
     cgPlot,xarr,yarr,psym=10,xst=4,ytickformat='exponent',charsize=1.0,$
            xr=[-1,3]
     plothist,alog10(av[where(av GT 0)]),bin=0.1,xarr,yarr,/noplot
     cgOplot,xarr,yarr,psym=10,color='orange'
     
     cgAxis,xaxis=0,xr=10.^(!x.crange),/xst,/save,charsize=1.0,$
            xtit='Virial Parameter',/xlog,$
            xtickformat='exponent10'
     cgAxis,xaxis=1,/xst,xtickformat='blank_axis'
     vline,1,color='cyan'
     
     al_legend,/top,/right,box=0,charsize=0.7,color=['black','orange'],$
               ['Dense Gas ','!u13!n13 CO ']+cgSymbol('alpha')+'!dvir!n',$
               linestyle=0,linsize=0.5
     
     
     myps,/done,/mp
     
     
     ;;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     ;; Now, actually slice and dice the damn thing!
     
     ;;)))))))))))))))))))))))))
     ;; Everything!
     iall = where( usei EQ usei, nall)
     print,'nALL: ',nall

     sl = {dist:dist[iall],mass:mass[iall],flux:flux[iall],arad:arad[iall],$
           tdus:tdus[iall],linw:linw[iall],dglw:dglw[iall],rgal:rgal[iall],$
           radi:radi[iall],usei:usei[iall],dens:dens[iall],nden:nden[iall],$
           sden:sden[iall],cden:cden[iall],avir:avir[iall],avdg:avdg[iall],$
           glon:glon[iall],glat:glat[iall],aspe:aspe[iall],sfac:sfac[iall]}
     save,sl,filename='./masses/save_files/sliced_all_td'+stdst+'.sav'


     ;;)))))))))))))))))))))))))
     ;; Distinct regions
     il30 = where( abs(glon - 30.d) LE 1.5, nl30)
     igem = where( abs(glon - 190.d) LE 10., ngem)
     print,'nL30: ',nl30
     print,'nGEM: ',ngem
     
     sl = {dist:dist[il30],mass:mass[il30],flux:flux[il30],arad:arad[il30],$
           tdus:tdus[il30],linw:linw[il30],dglw:dglw[il30],rgal:rgal[il30],$
           radi:radi[il30],usei:usei[il30],dens:dens[il30],nden:nden[il30],$
           sden:sden[il30],cden:cden[il30],avir:avir[il30],avdg:avdg[il30],$
           glon:glon[il30],glat:glat[il30],aspe:aspe[il30],sfac:sfac[il30]}
     save,sl,filename='./masses/save_files/sliced_l30_td'+stdst+'.sav'

     sl = {dist:dist[igem],mass:mass[igem],flux:flux[igem],arad:arad[igem],$
           tdus:tdus[igem],linw:linw[igem],dglw:dglw[igem],rgal:rgal[igem],$
           radi:radi[igem],usei:usei[igem],dens:dens[igem],nden:nden[igem],$
           sden:sden[igem],cden:cden[igem],avir:avir[igem],avdg:avdg[igem],$
           glon:glon[igem],glat:glat[igem],aspe:aspe[igem],sfac:sfac[igem]}
     save,sl,filename='./masses/save_files/sliced_gem_td'+stdst+'.sav'
     
     
     ;;)))))))))))))))))))))))))
     ;; Number Density
     insm = where( nden GE 1.d   AND nden LT 750.d, nnsm)
     inmd = where( nden GE 750.d AND nden LE 1.d4,  nnmd)
     inlg = where( nden GT 1.d4  AND nden LE 1.d6,  nnlg)
     print,'nNSM: ',nnsm
     print,'nNMD: ',nnmd
     print,'nNLG: ',nnlg

     sl = {dist:dist[insm],mass:mass[insm],flux:flux[insm],arad:arad[insm],$
           tdus:tdus[insm],linw:linw[insm],dglw:dglw[insm],rgal:rgal[insm],$
           radi:radi[insm],usei:usei[insm],dens:dens[insm],nden:nden[insm],$
           sden:sden[insm],cden:cden[insm],avir:avir[insm],avdg:avdg[insm],$
           glon:glon[insm],glat:glat[insm],aspe:aspe[insm],sfac:sfac[insm]}
     save,sl,filename='./masses/save_files/sliced_nsm_td'+stdst+'.sav'

     sl = {dist:dist[inmd],mass:mass[inmd],flux:flux[inmd],arad:arad[inmd],$
           tdus:tdus[inmd],linw:linw[inmd],dglw:dglw[inmd],rgal:rgal[inmd],$
           radi:radi[inmd],usei:usei[inmd],dens:dens[inmd],nden:nden[inmd],$
           sden:sden[inmd],cden:cden[inmd],avir:avir[inmd],avdg:avdg[inmd],$
           glon:glon[inmd],glat:glat[inmd],aspe:aspe[inmd],sfac:sfac[inmd]}
     save,sl,filename='./masses/save_files/sliced_nmd_td'+stdst+'.sav'

     sl = {dist:dist[inlg],mass:mass[inlg],flux:flux[inlg],arad:arad[inlg],$
           tdus:tdus[inlg],linw:linw[inlg],dglw:dglw[inlg],rgal:rgal[inlg],$
           radi:radi[inlg],usei:usei[inlg],dens:dens[inlg],nden:nden[inlg],$
           sden:sden[inlg],cden:cden[inlg],avir:avir[inlg],avdg:avdg[inlg],$
           glon:glon[inlg],glat:glat[inlg],aspe:aspe[inlg],sfac:sfac[inlg]}
     save,sl,filename='./masses/save_files/sliced_nlg_td'+stdst+'.sav'
     
     
     ;;)))))))))))))))))))))))))
     ;; Physical Radius
     irsm = where( radi GE 1.d-2  AND radi LT 0.125d, nrsm)
     irmd = where( radi GE 0.125d AND radi LE 1.25d,  nrmd)
     irlg = where( radi GT 1.25d  AND radi LE 1.d2,   nrlg)
     print,'nRSM: ',nrsm
     print,'nRMD: ',nrmd
     print,'nRLG: ',nrlg

     sl = {dist:dist[irsm],mass:mass[irsm],flux:flux[irsm],arad:arad[irsm],$
           tdus:tdus[irsm],linw:linw[irsm],dglw:dglw[irsm],rgal:rgal[irsm],$
           radi:radi[irsm],usei:usei[irsm],dens:dens[irsm],nden:nden[irsm],$
           sden:sden[irsm],cden:cden[irsm],avir:avir[irsm],avdg:avdg[irsm],$
           glon:glon[irsm],glat:glat[irsm],aspe:aspe[irsm],sfac:sfac[irsm]}
     save,sl,filename='./masses/save_files/sliced_rsm_td'+stdst+'.sav'

     sl = {dist:dist[irmd],mass:mass[irmd],flux:flux[irmd],arad:arad[irmd],$
           tdus:tdus[irmd],linw:linw[irmd],dglw:dglw[irmd],rgal:rgal[irmd],$
           radi:radi[irmd],usei:usei[irmd],dens:dens[irmd],nden:nden[irmd],$
           sden:sden[irmd],cden:cden[irmd],avir:avir[irmd],avdg:avdg[irmd],$
           glon:glon[irmd],glat:glat[irmd],aspe:aspe[irmd],sfac:sfac[irmd]}
     save,sl,filename='./masses/save_files/sliced_rmd_td'+stdst+'.sav'

     sl = {dist:dist[irlg],mass:mass[irlg],flux:flux[irlg],arad:arad[irlg],$
           tdus:tdus[irlg],linw:linw[irlg],dglw:dglw[irlg],rgal:rgal[irlg],$
           radi:radi[irlg],usei:usei[irlg],dens:dens[irlg],nden:nden[irlg],$
           sden:sden[irlg],cden:cden[irlg],avir:avir[irlg],avdg:avdg[irlg],$
           glon:glon[irlg],glat:glat[irlg],aspe:aspe[irlg],sfac:sfac[irlg]}
     save,sl,filename='./masses/save_files/sliced_rlg_td'+stdst+'.sav'
     
     
     ;;)))))))))))))))))))))))))
     ;; Galactocentric Radius
     print,'rgal: ',m4_stat(rgal)
     irg1 = where( rgal GE 2.d  AND rgal LT 4.,  nrg1)
     irg2 = where( rgal GE 4.d  AND rgal LT 6.,  nrg2)
     irg3 = where( rgal GE 6.d  AND rgal LT 8.,  nrg3)
     irg4 = where( rgal GE 8.d  AND rgal LT 10., nrg4)
     irg5 = where( rgal GE 10.d AND rgal LT 12., nrg5)
     irg6 = where( rgal GE 12.d AND rgal LT 14., nrg6)
     irg7 = where( rgal GE 14.d AND rgal LT 16., nrg7)
     print,'nRG1: ',nrg1
     print,'nRG2: ',nrg2
     print,'nRG3: ',nrg3
     print,'nRG4: ',nrg4
     print,'nRG5: ',nrg5
     print,'nRG6: ',nrg6
     print,'nRG7: ',nrg7

     sl = {dist:dist[irg1],mass:mass[irg1],flux:flux[irg1],arad:arad[irg1],$
           tdus:tdus[irg1],linw:linw[irg1],dglw:dglw[irg1],rgal:rgal[irg1],$
           radi:radi[irg1],usei:usei[irg1],dens:dens[irg1],nden:nden[irg1],$
           sden:sden[irg1],cden:cden[irg1],avir:avir[irg1],avdg:avdg[irg1],$
           glon:glon[irg1],glat:glat[irg1],aspe:aspe[irg1],sfac:sfac[irg1]}
     save,sl,filename='./masses/save_files/sliced_rg1_td'+stdst+'.sav'

     sl = {dist:dist[irg2],mass:mass[irg2],flux:flux[irg2],arad:arad[irg2],$
           tdus:tdus[irg2],linw:linw[irg2],dglw:dglw[irg2],rgal:rgal[irg2],$
           radi:radi[irg2],usei:usei[irg2],dens:dens[irg2],nden:nden[irg2],$
           sden:sden[irg2],cden:cden[irg2],avir:avir[irg2],avdg:avdg[irg2],$
           glon:glon[irg2],glat:glat[irg2],aspe:aspe[irg2],sfac:sfac[irg2]}
     save,sl,filename='./masses/save_files/sliced_rg2_td'+stdst+'.sav'

     sl = {dist:dist[irg3],mass:mass[irg3],flux:flux[irg3],arad:arad[irg3],$
           tdus:tdus[irg3],linw:linw[irg3],dglw:dglw[irg3],rgal:rgal[irg3],$
           radi:radi[irg3],usei:usei[irg3],dens:dens[irg3],nden:nden[irg3],$
           sden:sden[irg3],cden:cden[irg3],avir:avir[irg3],avdg:avdg[irg3],$
           glon:glon[irg3],glat:glat[irg3],aspe:aspe[irg3],sfac:sfac[irg3]}
     save,sl,filename='./masses/save_files/sliced_rg3_td'+stdst+'.sav'

     sl = {dist:dist[irg4],mass:mass[irg4],flux:flux[irg4],arad:arad[irg4],$
           tdus:tdus[irg4],linw:linw[irg4],dglw:dglw[irg4],rgal:rgal[irg4],$
           radi:radi[irg4],usei:usei[irg4],dens:dens[irg4],nden:nden[irg4],$
           sden:sden[irg4],cden:cden[irg4],avir:avir[irg4],avdg:avdg[irg4],$
           glon:glon[irg4],glat:glat[irg4],aspe:aspe[irg4],sfac:sfac[irg4]}
     save,sl,filename='./masses/save_files/sliced_rg4_td'+stdst+'.sav'

     sl = {dist:dist[irg5],mass:mass[irg5],flux:flux[irg5],arad:arad[irg5],$
           tdus:tdus[irg5],linw:linw[irg5],dglw:dglw[irg5],rgal:rgal[irg5],$
           radi:radi[irg5],usei:usei[irg5],dens:dens[irg5],nden:nden[irg5],$
           sden:sden[irg5],cden:cden[irg5],avir:avir[irg5],avdg:avdg[irg5],$
           glon:glon[irg5],glat:glat[irg5],aspe:aspe[irg5],sfac:sfac[irg5]}
     save,sl,filename='./masses/save_files/sliced_rg5_td'+stdst+'.sav'

     sl = {dist:dist[irg6],mass:mass[irg6],flux:flux[irg6],arad:arad[irg6],$
           tdus:tdus[irg6],linw:linw[irg6],dglw:dglw[irg6],rgal:rgal[irg6],$
           radi:radi[irg6],usei:usei[irg6],dens:dens[irg6],nden:nden[irg6],$
           sden:sden[irg6],cden:cden[irg6],avir:avir[irg6],avdg:avdg[irg6],$
           glon:glon[irg6],glat:glat[irg6],aspe:aspe[irg6],sfac:sfac[irg6]}
     save,sl,filename='./masses/save_files/sliced_rg6_td'+stdst+'.sav'

     sl = {dist:dist[irg7],mass:mass[irg7],flux:flux[irg7],arad:arad[irg7],$
           tdus:tdus[irg7],linw:linw[irg7],dglw:dglw[irg7],rgal:rgal[irg7],$
           radi:radi[irg7],usei:usei[irg7],dens:dens[irg7],nden:nden[irg7],$
           sden:sden[irg7],cden:cden[irg7],avir:avir[irg7],avdg:avdg[irg7],$
           glon:glon[irg7],glat:glat[irg7],aspe:aspe[irg7],sfac:sfac[irg7]}
     save,sl,filename='./masses/save_files/sliced_rg7_td'+stdst+'.sav'
     
     
     ;;)))))))))))))))))))))))))
     ;; Heliocentric Distance
     print,'dist: ',m4_stat(dist)
     idh0 = where( dist GE 0.2d AND dist LT 2.,  ndh0)
     idh1 = where( dist GE 2.d  AND dist LT 4.,  ndh1)
     idh2 = where( dist GE 4.d  AND dist LT 6.,  ndh2)
     idh3 = where( dist GE 6.d  AND dist LT 8.,  ndh3)
     idh4 = where( dist GE 8.d  AND dist LT 10., ndh4)
     idh5 = where( dist GE 10.d AND dist LT 12., ndh5)
     idh6 = where( dist GE 12.d AND dist LT 14., ndh6)
     idh7 = where( dist GE 14.d AND dist LT 16., ndh7)
     idh8 = where( dist GE 16.d AND dist LT 18., ndh8)
     idh9 = where( dist GE 18.d AND dist LT 20., ndh9)
     print,'nDH0: ',ndh0
     print,'nDH1: ',ndh1
     print,'nDH2: ',ndh2
     print,'nDH3: ',ndh3
     print,'nDH4: ',ndh4
     print,'nDH5: ',ndh5
     print,'nDH6: ',ndh6
     print,'nDH7: ',ndh7
     print,'nDH8: ',ndh8
     print,'nDH9: ',ndh9

     sl = {dist:dist[idh0],mass:mass[idh0],flux:flux[idh0],arad:arad[idh0],$
           tdus:tdus[idh0],linw:linw[idh0],dglw:dglw[idh0],rgal:rgal[idh0],$
           radi:radi[idh0],usei:usei[idh0],dens:dens[idh0],nden:nden[idh0],$
           sden:sden[idh0],cden:cden[idh0],avir:avir[idh0],avdg:avdg[idh0],$
           glon:glon[idh0],glat:glat[idh0],aspe:aspe[idh0],sfac:sfac[idh0]}
     save,sl,filename='./masses/save_files/sliced_dh0_td'+stdst+'.sav'

     sl = {dist:dist[idh1],mass:mass[idh1],flux:flux[idh1],arad:arad[idh1],$
           tdus:tdus[idh1],linw:linw[idh1],dglw:dglw[idh1],rgal:rgal[idh1],$
           radi:radi[idh1],usei:usei[idh1],dens:dens[idh1],nden:nden[idh1],$
           sden:sden[idh1],cden:cden[idh1],avir:avir[idh1],avdg:avdg[idh1],$
           glon:glon[idh1],glat:glat[idh1],aspe:aspe[idh1],sfac:sfac[idh1]}
     save,sl,filename='./masses/save_files/sliced_dh1_td'+stdst+'.sav'

     sl = {dist:dist[idh2],mass:mass[idh2],flux:flux[idh2],arad:arad[idh2],$
           tdus:tdus[idh2],linw:linw[idh2],dglw:dglw[idh2],rgal:rgal[idh2],$
           radi:radi[idh2],usei:usei[idh2],dens:dens[idh2],nden:nden[idh2],$
           sden:sden[idh2],cden:cden[idh2],avir:avir[idh2],avdg:avdg[idh2],$
           glon:glon[idh2],glat:glat[idh2],aspe:aspe[idh2],sfac:sfac[idh2]}
     save,sl,filename='./masses/save_files/sliced_dh2_td'+stdst+'.sav'

     sl = {dist:dist[idh3],mass:mass[idh3],flux:flux[idh3],arad:arad[idh3],$
           tdus:tdus[idh3],linw:linw[idh3],dglw:dglw[idh3],rgal:rgal[idh3],$
           radi:radi[idh3],usei:usei[idh3],dens:dens[idh3],nden:nden[idh3],$
           sden:sden[idh3],cden:cden[idh3],avir:avir[idh3],avdg:avdg[idh3],$
           glon:glon[idh3],glat:glat[idh3],aspe:aspe[idh3],sfac:sfac[idh3]}
     save,sl,filename='./masses/save_files/sliced_dh3_td'+stdst+'.sav'

     sl = {dist:dist[idh4],mass:mass[idh4],flux:flux[idh4],arad:arad[idh4],$
           tdus:tdus[idh4],linw:linw[idh4],dglw:dglw[idh4],rgal:rgal[idh4],$
           radi:radi[idh4],usei:usei[idh4],dens:dens[idh4],nden:nden[idh4],$
           sden:sden[idh4],cden:cden[idh4],avir:avir[idh4],avdg:avdg[idh4],$
           glon:glon[idh4],glat:glat[idh4],aspe:aspe[idh4],sfac:sfac[idh4]}
     save,sl,filename='./masses/save_files/sliced_dh4_td'+stdst+'.sav'

     sl = {dist:dist[idh5],mass:mass[idh5],flux:flux[idh5],arad:arad[idh5],$
           tdus:tdus[idh5],linw:linw[idh5],dglw:dglw[idh5],rgal:rgal[idh5],$
           radi:radi[idh5],usei:usei[idh5],dens:dens[idh5],nden:nden[idh5],$
           sden:sden[idh5],cden:cden[idh5],avir:avir[idh5],avdg:avdg[idh5],$
           glon:glon[idh5],glat:glat[idh5],aspe:aspe[idh5],sfac:sfac[idh5]}
     save,sl,filename='./masses/save_files/sliced_dh5_td'+stdst+'.sav'

     sl = {dist:dist[idh6],mass:mass[idh6],flux:flux[idh6],arad:arad[idh6],$
           tdus:tdus[idh6],linw:linw[idh6],dglw:dglw[idh6],rgal:rgal[idh6],$
           radi:radi[idh6],usei:usei[idh6],dens:dens[idh6],nden:nden[idh6],$
           sden:sden[idh6],cden:cden[idh6],avir:avir[idh6],avdg:avdg[idh6],$
           glon:glon[idh6],glat:glat[idh6],aspe:aspe[idh6],sfac:sfac[idh6]}
     save,sl,filename='./masses/save_files/sliced_dh6_td'+stdst+'.sav'

     sl = {dist:dist[idh7],mass:mass[idh7],flux:flux[idh7],arad:arad[idh7],$
           tdus:tdus[idh7],linw:linw[idh7],dglw:dglw[idh7],rgal:rgal[idh7],$
           radi:radi[idh7],usei:usei[idh7],dens:dens[idh7],nden:nden[idh7],$
           sden:sden[idh7],cden:cden[idh7],avir:avir[idh7],avdg:avdg[idh7],$
           glon:glon[idh7],glat:glat[idh7],aspe:aspe[idh7],sfac:sfac[idh7]}
     save,sl,filename='./masses/save_files/sliced_dh7_td'+stdst+'.sav'

     sl = {dist:dist[idh8],mass:mass[idh8],flux:flux[idh8],arad:arad[idh8],$
           tdus:tdus[idh8],linw:linw[idh8],dglw:dglw[idh8],rgal:rgal[idh8],$
           radi:radi[idh8],usei:usei[idh8],dens:dens[idh8],nden:nden[idh8],$
           sden:sden[idh8],cden:cden[idh8],avir:avir[idh8],avdg:avdg[idh8],$
           glon:glon[idh8],glat:glat[idh8],aspe:aspe[idh8],sfac:sfac[idh8]}
     save,sl,filename='./masses/save_files/sliced_dh8_td'+stdst+'.sav'

     sl = {dist:dist[idh9],mass:mass[idh9],flux:flux[idh9],arad:arad[idh9],$
           tdus:tdus[idh9],linw:linw[idh9],dglw:dglw[idh9],rgal:rgal[idh9],$
           radi:radi[idh9],usei:usei[idh9],dens:dens[idh9],nden:nden[idh9],$
           sden:sden[idh9],cden:cden[idh9],avir:avir[idh9],avdg:avdg[idh9],$
           glon:glon[idh9],glat:glat[idh9],aspe:aspe[idh9],sfac:sfac[idh9]}
     save,sl,filename='./masses/save_files/sliced_dh9_td'+stdst+'.sav'
     
     
     ;;)))))))))))))))))))))))))
     ;; Star Formation Activity
     print,'sfac: ',m4_stat(sfac)
     isf0 = where( sfac GE -.5d AND sfac LT 0.5d, nsf0)
     isf1 = where( sfac GE 0.5d AND sfac LT 1.5d, nsf1)
     isf2 = where( sfac GE 1.5d AND sfac LT 2.5d, nsf2)
     isf3 = where( sfac GE 2.5d AND sfac LT 3.5d, nsf3)
     print,'nSF0: ',nsf0
     print,'nSF1: ',nsf1
     print,'nSF2: ',nsf2
     print,'nSF3: ',nsf3

     sl = {dist:dist[isf0],mass:mass[isf0],flux:flux[isf0],arad:arad[isf0],$
           tdus:tdus[isf0],linw:linw[isf0],dglw:dglw[isf0],rgal:rgal[isf0],$
           radi:radi[isf0],usei:usei[isf0],dens:dens[isf0],nden:nden[isf0],$
           sden:sden[isf0],cden:cden[isf0],avir:avir[isf0],avdg:avdg[isf0],$
           glon:glon[isf0],glat:glat[isf0],aspe:aspe[isf0],sfac:sfac[isf0]}
     save,sl,filename='./masses/save_files/sliced_sf0_td'+stdst+'.sav'

     sl = {dist:dist[isf1],mass:mass[isf1],flux:flux[isf1],arad:arad[isf1],$
           tdus:tdus[isf1],linw:linw[isf1],dglw:dglw[isf1],rgal:rgal[isf1],$
           radi:radi[isf1],usei:usei[isf1],dens:dens[isf1],nden:nden[isf1],$
           sden:sden[isf1],cden:cden[isf1],avir:avir[isf1],avdg:avdg[isf1],$
           glon:glon[isf1],glat:glat[isf1],aspe:aspe[isf1],sfac:sfac[isf1]}
     save,sl,filename='./masses/save_files/sliced_sf1_td'+stdst+'.sav'

     sl = {dist:dist[isf2],mass:mass[isf2],flux:flux[isf2],arad:arad[isf2],$
           tdus:tdus[isf2],linw:linw[isf2],dglw:dglw[isf2],rgal:rgal[isf2],$
           radi:radi[isf2],usei:usei[isf2],dens:dens[isf2],nden:nden[isf2],$
           sden:sden[isf2],cden:cden[isf2],avir:avir[isf2],avdg:avdg[isf2],$
           glon:glon[isf2],glat:glat[isf2],aspe:aspe[isf2],sfac:sfac[isf2]}
     save,sl,filename='./masses/save_files/sliced_sf2_td'+stdst+'.sav'

     sl = {dist:dist[isf3],mass:mass[isf3],flux:flux[isf3],arad:arad[isf3],$
           tdus:tdus[isf3],linw:linw[isf3],dglw:dglw[isf3],rgal:rgal[isf3],$
           radi:radi[isf3],usei:usei[isf3],dens:dens[isf3],nden:nden[isf3],$
           sden:sden[isf3],cden:cden[isf3],avir:avir[isf3],avdg:avdg[isf3],$
           glon:glon[isf3],glat:glat[isf3],aspe:aspe[isf3],sfac:sfac[isf3]}
     save,sl,filename='./masses/save_files/sliced_sf3_td'+stdst+'.sav'
     
     
     
     
     
     
     
     
     
     
     
     
     
     
  ENDFOR                        ; SampleTd Loop
  
  
  
END





